﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microhard.YYKid.SecondHand.Interfaces;
using Microhard.YYKid.SecondHand.Impls;
using Microhard.YYKid.SecondHand.DTO;
using Microhard.Core;
using System.Configuration;
using Microhard.WeixinMP.Unities;
using Microhard.Core.Mail;

namespace TestProject
{
    [TestClass]
    public class Test58
    {
        [TestMethod]
        public void TestMethod1()
        {
            Log.Info("BuzService.OnStart", "服务开始" + DateTime.Now);

            //获取最新的销售信息
            KidModelMapper.InitMap();
            IRead58 ir = new _58ItemDataParser();
            var newposts = ir.GetNewPost("yingyou", "wh");
            //使用微信发送

            if (newposts != null && newposts.Count > 0)
            {
                string msgTemplate = "标题:{0}\r\n内容:{1}\r\n地址:{2}";
                var toFakeIDs = ConfigurationManager.AppSettings["ToFakeIds"];
                var mpAccount = ConfigurationManager.AppSettings["MPAccount"];
                var mppwd = ConfigurationManager.AppSettings["MPAccountPWD"];
                foreach (var u in toFakeIDs.Split(new char[] { ',' }))
                {
                    foreach (var n in newposts)
                    {
                        var msg = string.Format(msgTemplate, n.Title, n.Description, n.Url);
                        Log.Info("BuzService.OnStart", msg);
                        
                        MailTool.SendMailWithSMTP("445011468@qq.com", "48482293@qq.com", "58同城母婴二手信息", msg, "smtp.qq.com", "25", "445011468@qq.com", "123abc123");
                    }
                }
            }
        }
    }
}
